{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "c0e26b7e",
   "metadata": {},
   "outputs": [],
   "source": [
    "#用户输入"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "0154383d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "name: junk\n",
      "age:19\n",
      "job:student\n",
      "salary:0\n"
     ]
    }
   ],
   "source": [
    "# 用户输入和格式化打印\n",
    "\n",
    "name = input(\"name: \")\n",
    "age = input(\"age:\")\n",
    "job = input(\"job:\")\n",
    "salary = input(\"salary:\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "41e93325",
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-----------INFOjunk----------\n",
      "age: 19\n",
      "job: student\n",
      "salary: 0\n"
     ]
    }
   ],
   "source": [
    "# name 动态的出现在字符串中\n",
    "info = '''-----------INFO''' + name + '''----------\n",
    "age: '''+ age + '''\n",
    "job: '''+ job + '''\n",
    "salary: '''+ salary\n",
    "\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "58918af1",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 优化字符串拼接 ： 占位符 %s 动态的数据-->变量\n",
    "# 优势:  1.全部都写在一个大写的字符串里面\n",
    "#       2.省略了“+”符号\n",
    "# 缺点:  如果有几百个需要填进去的内容，容易顺序乱掉，出现打印结果的不正确"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "85b1c68b",
   "metadata": {},
   "outputs": [],
   "source": [
    "info_占位符 = '''-----------INFO %s ----------\n",
    "name: %s\n",
    "job: %s\n",
    "salary: %s'''%(name,name,age,job,salary)\n",
    "\n",
    "print(info_占位符)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "8a0c6c9e",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid character in identifier (<ipython-input-6-851b70f66847>, line 7)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-6-851b70f66847>\"\u001b[1;36m, line \u001b[1;32m7\u001b[0m\n\u001b[1;33m    salary:{薪水}'''.format(姓名=name,年龄=age，工作=job，薪水=salary)\u001b[0m\n\u001b[1;37m                                                          \n^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid character in identifier\n"
     ]
    }
   ],
   "source": [
    "#优化： .format（） 格式化 字符串\n",
    "\n",
    "info_format ='''----------INFO {姓名}----------\n",
    "name:{姓名}\n",
    "age:{年龄}\n",
    "job:{工作}\n",
    "salary:{薪水}'''.format(姓名=name,年龄=age，工作=job，薪水=salary)\n",
    "\n",
    "print（info_format）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "a7e23f90",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name '完整的高教动态所有页面url' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-4-5bedf1b9a347>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m     11\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m27\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     12\u001b[0m     \u001b[0m完整的高校动态所有页面url\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m\"https://www.nfu.edu.cn/{新闻}/index{页码}。htm\"\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mformat\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0m页码\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mstr\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0m新闻\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m\"ztb\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 13\u001b[1;33m     \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0m完整的高教动态所有页面url\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m: name '完整的高教动态所有页面url' is not defined"
     ]
    }
   ],
   "source": [
    "# .format()案例\n",
    "url = \"https://www.nfu.edu.cn\" #官网的域名\n",
    "# 目标获取高教动态的所有uri链接\n",
    "高教动态 = \"gjdt\"\n",
    "url_页面 = \".htm\"\n",
    "url_页面细节不变 =\"/index\"\n",
    "# for i in range(1,27):\n",
    "#  完整的高教动态所有页面url = url+高教动态+ url_页面细节不变 + str(i) + url_页面\n",
    "#  print(完整的高教动态所有页面url)\n",
    "\n",
    "for i in range(1,27):\n",
    "    完整的高校动态所有页面url = \"https://www.nfu.edu.cn/{新闻}/index{页码}。htm\".format(页码=str(i),新闻=\"ztb\")\n",
    "    print(完整的高教动态所有页面url)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fe700db2",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
